package com.aidex.tina.controller;

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.R;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import com.aidex.framework.cache.DictUtils;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.tina.domain.Supplier;
import com.aidex.tina.service.SupplierService;

/**
 * 供应商管理Controller
 * @author Stanfine
 * @email shanliang@outlook.com
 * @date 2022-06-08
 */
@RestController
@RequestMapping("/tina/Supplier")
public class SupplierController extends BaseController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 查询供应商管理列表
     */
    @PreAuthorize("@ss.hasPermi('tina:Supplier:list')")
    @GetMapping("/list")
    public R<PageInfo> list(Supplier supplier, HttpServletRequest request, HttpServletResponse response) {
        supplier.setPage(new PageDomain(request, response));
        return R.data(supplierService.findPage(supplier));
    }

    /**
     * 获取供应商管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('tina:Supplier:query')")
    @GetMapping(value = "/{id}")
    public R<Supplier> detail(@PathVariable("id") String id) {
        return R.data(supplierService.get(id));
    }

    /**
     * 新增供应商管理
     */
    @PreAuthorize("@ss.hasPermi('tina:Supplier:add')")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  Supplier supplier) {
        return R.status(supplierService.save(supplier));
    }

    /**
     * 修改供应商管理
     */
    @PreAuthorize("@ss.hasPermi('tina:Supplier:edit')")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated Supplier supplier) {
        return R.status(supplierService.save(supplier));
    }

    /**
     * 删除供应商管理
     */
    @PreAuthorize("@ss.hasPermi('tina:Supplier:remove')")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids) {
        return R.status(supplierService.deleteSupplierByIds(ids));
    }


    /**
     * 导出供应商管理列表
     */
    @PreAuthorize("@ss.hasPermi('tina:Supplier:export')")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(Supplier supplier) {
        List<Supplier> list = supplierService.findList(supplier);
        ExcelUtil<Supplier> util = new ExcelUtil<Supplier>(Supplier.class);
        return util.exportExcel(list, "供应商管理数据");
    }
	
    /**
     * 根据字典类型查询字典数据信息等其他自定义信息
     */
    @GetMapping(value = "/getInitData/{dictTypes}")
    public R getInitData(@PathVariable String dictTypes) {
        Map<String, Object> dataMap = new HashMap<String, Object>();
        dataMap.putAll(DictUtils.getMultiDictList(dictTypes));
        return R.data(dataMap);
    }

}
